module.exports = function ($scope, $modal, $resource, $state, getDmwSaleList, createSaleDmw, deleteSaleDmwById, getSaleList, pushSaleToDmw) {

	$scope.searchform = {};
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10;         //每页显示几条

	$scope.load = function() {
		var para = {
			pageNo:$scope.bigCurrentPage, 
			pageSize:$scope.itemsPerPage
		};
    para = angular.extend($scope.searchform, para); 
    getDmwSaleList.save(para, function (res) {
			if (res.errcode === 0) {
				$scope.objs = res.data.results;
				$scope.bigTotalItems = res.data.totalRecord;
			} else {
				alert(res.errmsg);
			}
		});
	}
	$scope.load();

	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.load();
		}
	};


	// 打开模态框
	$scope.add = function () {
    var createSaleDmw1 = createSaleDmw;
    var getSaleList1 = getSaleList;
		var modalInstance = $modal.open({
			template: require('../views/create_dmw_product.html'),
			controller: 'create_dmw_product',
			size: 'lg',
			resolve: {
				'createSaleDmw': function () {
					return createSaleDmw1;
				},
				'getSaleList': function () {
					return getSaleList1;
				}
			}
		});
		modalInstance.result.then(function () {
			$scope.load();
		});
  }
  // 同步
  $scope.synchro = function (id) {
    if (confirm('确定同步吗？')) {
      pushSaleToDmw.save({'id' : id}, function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: '', body: '同步成功！' })
          $scope.load();
        } else {
          alert(res.errmsg);
        }
      });
    }
  };
  // 删除
  $scope.delete = function (id) {
    if (confirm('确定删除吗？')) {
      deleteSaleDmwById.save({'id' : id}, function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: '', body: '删除成功！' })
          $scope.load();
        } else {
          alert(res.errmsg);
        }
      });
    }
  };
  $scope.addPermission = function () {
    $state.go('app.createLongPay');
  }
	$scope.edit = function (obj) {
    console.log(obj)
		$state.go('app.createLongPay', { 'id': obj.id });
	};

	// $scope.create = function () {
	// 	$state.go('app.deviceCreate', {});
	// }

	// $scope.addDevice = function(){
	// 	$resource('/api/ac/tc/ticketDeviceService/createWxDeviceCheckCode', {}, {}).save({'view': $scope.searchform.view}, function(res){
	// 		if (res.errcode === 0){
	// 			var modalInstance = $modal.open({
	// 				template: require('../views/tourQrcode.html'),
	// 				controller: 'tourQrcode',
	// 				size: 'sm',
	// 				resolve: {
	// 					qrcode: function () {
	// 						return res.data.result.url;
	// 					}
	// 				}
	// 			});
	// 			modalInstance.result.then(function () {
	// 				$scope.load();
	// 			});
	// 		} else {
	// 			toaster.error({title: '', body: '生成二维码失败'});
	// 		}
	// 	});
		
	// }
};